package demo;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;

public class Test {
    public static void main(String[] args) {
       // BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(1000);
        MyBlockQueue queue = new MyBlockQueue(1000);
        //生产者线程
        Thread t1 = new Thread(()-> {
           int i = 1;
           while (true){

               try {
                   queue.put(""+i);
                   System.out.println("生产元素"+ i);
                   i++;
                   //给生产操作加sleep
                  Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        //消费者线程
        Thread t2 =new Thread(()->{
           while (true){
               try {
                   Integer i =Integer.parseInt(queue.take()) ;
                   System.out.println("消费者元素"+i);
                   //Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        t1.start();
        t2.start();
    }

}
